﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.Mvc;

namespace LifeTree.Mvc.Helpers
{
    public class ViewHelper : IViewHelper
    {
        public string RenderPartialView(ControllerContext controllerContext, string partialViewName, object model)
        {
            StringWriter writer = new StringWriter();
            var view = ViewEngines.Engines.FindPartialView(controllerContext, partialViewName);
            ViewDataDictionary viewData = new ViewDataDictionary(model);
            ViewContext viewContext = new ViewContext(controllerContext, view.View, viewData, controllerContext.Controller.TempData, writer);
            view.View.Render(viewContext, writer);
            return writer.GetStringBuilder().ToString();
        }
    }
}
